﻿using System;
using MathNet.Numerics.LinearAlgebra.Double;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Marvin.Tests.TrainingSetTests
{
    [TestClass]
    public class FourDimensionalTrainingSetAllowsAddingValidData
    {
        private TrainingSet<double> _trainingSet;
        private static readonly double[] InputDatum = new[] {1.0, 2.0, 3.0, 4.0};
        private static readonly DenseVector InputDatumAsVector = new DenseVector(InputDatum); 
        private const int NumberOfTrainingExamples = 10; 

        [TestInitialize]
        public void InitializeFourDimensionalTrainingSet()
        {
            _trainingSet = new TrainingSet<double>(4, NumberOfTrainingExamples);
        }

        [ExpectedException(typeof (ArgumentException))]
        [TestMethod]
        public void AddingANullValueThrowsAnExcpetion()
        {
            _trainingSet.Add(null, 0.0);
        }


        [TestMethod]
        public void AddedDatumIsAddedToTheMatrix()
        {
            _trainingSet.Add(InputDatum, 0.0);
            var matrix = _trainingSet.GetX();
            var firstRow = matrix.Row(0);

            Assert.AreEqual(InputDatumAsVector, firstRow);
        }


        [TestMethod]
        public void TrainingSetIsNotBehavingLikeASetButAllowsDuplicateData()
        {
            _trainingSet.Add(InputDatum, 0.0);
            _trainingSet.Add(InputDatum, 0.0);
            var matrix = _trainingSet.GetX();
            var secondRow = matrix.Row(1);
            

            Assert.AreEqual(InputDatumAsVector, secondRow);
        }

        [TestMethod]
        public void InitializeFeaturesWithFiveWillSetNumberOfFeaturesPropertyToFive()
        {
            var fiveDimensionalTrainingSet = new TrainingSet<double>(5, NumberOfTrainingExamples); 
            Assert.AreEqual(5, fiveDimensionalTrainingSet.Dimensions);
        }

        [TestMethod]
        public void InitializeFeaturesWithFourWillSetNumberOfFeaturesPropertyToFour()
        {
            var fourDimensionalTrainingSet = new TrainingSet<double>(4, NumberOfTrainingExamples);
            Assert.AreEqual(4, fourDimensionalTrainingSet.Dimensions);
        }
    }
}
